/*
 * main.c
 *
 *  Created on: Feb 17, 2013
 *      Author: justin
 */

#include "project.h"

#define spiPort1 1

int main() {
	spi_init();		//
	sbi(DDRB,spiPort1);
	int j=0;
	int i = 0;

	uint8_t writeEnable = FALSE,    //
			buffered = FALSE,    //
			gain = TRUE,    //
			shutdown = TRUE;

	uint8_t dacMsb, dacLsb, dacValue;
	dacValue = 127;

	while (1) {
		dacMsb = (writeEnable << 7) |    //shift the control and data appropriately.
				(buffered << 6) |    //The data is then logical OR'd together.
				(gain << 5) |    //j
				(shutdown << 4) |    //j
				((dacValue & 0xf0) >> 4);

		dacLsb = ((dacValue & 0x0f) << 4);
		cbi(PORTB,DDB2);
		spiWriteString(&dacMsb,1);
		spiWriteString(&dacLsb,1);
		sbi(PORTB,DDB2);
		i=i+1-j;
		dacValue=(i);
		if (i==255) j=2;
		if (i==0) j=0;


	}

	return 0;
}
